
'--------------------------------------------------------
' 执行所有测试用例
'--------------------------------------------------------
Private Sub test_LinkedHashSet_ALL_case()
    ' MergeSet 测试
    test_LinkedHashSet_MergeSet
    ' RemoveSet 测试
    test_LinkedHashSet_RemoveSet

    ' mergeObjArrayRef 测试
    test_LinkedHashSet_mergeObjArrayRef
    ' mergePrimitiveArrayRef 测试
    test_LinkedHashSet_mergePrimitiveArrayRef
    ' IObjArrayRef 测试
    test_LinkedHashSet_toObjArrayRef
    ' IObjArrayRef 测试: 异常测试，set 内同时包含基础数据类型 + 对象数据类型的数据
    test_LinkedHashSet_toObjArrayRef_error
    ' toPrimitiveArrayRef 测试
    test_LinkedHashSet_toPrimitiveArrayRef
    ' toPrimitiveArrayRef 测试: 异常测试，set 内同时包含基础数据类型 + 对象数据类型的数据
    test_LinkedHashSet_toPrimitiveArrayRef_error
End Sub

'--------------------------------------------------------
' 各方法的用例
'--------------------------------------------------------
' MergeSet 测试
Private Sub test_LinkedHashSet_MergeSet()
    ' 1. 生成 Set 对象
    Dim s1 As ISet
    Set s1 = UtilsSet.createLinkedHashSet
    Dim s2 As ISet
    Set s2 = UtilsSet.createLinkedHashSet

    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection

    ' 2. 检查 Add 的结果
    s1.Add "k11"
    s1.Add "k12"
    s1.Add "kx"
    s1.Add c1
    Debug.Assert s1.Count = 4

    ' 3. 创建第二个 set，并检查其 Add 的结果
    s2.Add "k21"
    s2.Add "k22"
    s2.Add "kx" ' <-- 这里构造一个和 s1 重复的数据
    s2.Add c2

    ' 4. 将 s2 合并到 s1 内
    s1.MergeSet s2

    ' 5. 检查合并的结果
    Debug.Assert s1.Count = 7
    Debug.Assert s1.Exists("k11")
    Debug.Assert s1.Exists("k12")
    Debug.Assert s1.Exists("kx")
    Debug.Assert s1.Exists("k21")
    Debug.Assert s1.Exists("k22")
    Debug.Assert s1.Exists(c1)
    Debug.Assert s1.Exists(c2)

    Debug.Assert s2.Count = 4
    Debug.Assert s2.Exists("k21")
    Debug.Assert s2.Exists("k22")
    Debug.Assert s2.Exists("kx")
    Debug.Assert s2.Exists(c2)
End Sub

' RemoveSet 测试
Private Sub test_LinkedHashSet_RemoveSet()
    ' 1. 生成 Set 对象
    Dim s1 As ISet
    Set s1 = UtilsSet.createLinkedHashSet
    Dim s2 As ISet
    Set s2 = UtilsSet.createLinkedHashSet

    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection

    ' 2. 检查 Add 的结果
    s1.Add "k11"
    s1.Add "k12"
    s1.Add "kx"
    s1.Add c1
    Debug.Assert s1.Count = 4

    ' 3. 创建第二个 set，并检查其 Add 的结果
    s2.Add "k21"
    s2.Add "k22"
    s2.Add "kx" ' <-- 这里构造一个和 s1 重复的数据
    s2.Add c2

    ' 4. 从 s1 内删除 s2 中的元素
    s1.RemoveSet s2

    ' 5. 检查合并的结果
    Debug.Assert s1.Count = 3
    Debug.Assert s1.Exists("k11")
    Debug.Assert s1.Exists("k12")
    Debug.Assert s1.Exists(c1)

    Debug.Assert s2.Count = 4
    Debug.Assert s2.Exists("k21")
    Debug.Assert s2.Exists("k22")
    Debug.Assert s2.Exists("kx")
    Debug.Assert s2.Exists(c2)
End Sub

' mergeObjArrayRef 测试
Private Sub test_LinkedHashSet_mergeObjArrayRef()
    ' 1. 生成 Set 对象
    Dim s As ISet
    Set s = UtilsSet.createLinkedHashSet

    ' 2. 创建 IObjArrayRef
    Dim arr As IObjArrayRef
    Set arr = UtilsArrayRef.createRealObjArrayRef

    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection
    Dim c3 As Collection
    Set c3 = New Collection

    arr.Add c1
    arr.Add c2
    arr.Add c3

    ' 3. 合并数据
    s.mergeObjArrayRef arr

    ' 4. 检查操作结果
    Dim c4 As Collection
    Set c4 = New Collection
    Debug.Assert s.Count = 3
    Debug.Assert s.Exists(c1)
    Debug.Assert s.Exists(c2)
    Debug.Assert s.Exists(c3)
    Debug.Assert Not s.Exists(c4)
End Sub

' mergePrimitiveArrayRef 测试
Private Sub test_LinkedHashSet_mergePrimitiveArrayRef()
    ' 1. 生成 Set 对象
    Dim s As ISet
    Set s = UtilsSet.createLinkedHashSet

    ' 2. 创建 IObjArrayRef
    Dim arr As IPrimitiveArrayRef
    Set arr = UtilsArrayRef.createRealPrimitiveArrayRef

    arr.Add "c1"
    arr.Add "c2"
    arr.Add "c3"

    ' 3. 合并数据
    s.mergePrimitiveArrayRef arr

    ' 4. 检查操作结果
    Debug.Assert s.Count = 3
    Debug.Assert s.Exists("c1")
    Debug.Assert s.Exists("c2")
    Debug.Assert s.Exists("c3")
    Debug.Assert Not s.Exists("c4")
End Sub

' IObjArrayRef 测试
Private Sub test_LinkedHashSet_toObjArrayRef()
    ' 1. 生成 Set 对象
    Dim s As ISet
    Set s = UtilsSet.createLinkedHashSet

    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection
    Dim c3 As Collection
    Set c3 = New Collection

    s.Add c1
    s.Add c2
    s.Add c3

    ' 2. 将 set 对象转换为 ObjArray
    Dim arr As IObjArrayRef
    Set arr = s.toObjArrayRef

    ' 3. 检查转换结果
    Debug.Assert arr.Count = 3

    ' 创建一个新的 set 来合并数组引用并进行检查
    Dim s2 As ISet
    Set s2 = UtilsSet.createLinkedHashSet
    s2.mergeObjArrayRef arr

    Debug.Assert s2.Count = 3
    Debug.Assert s2.Exists(c1)
    Debug.Assert s2.Exists(c2)
    Debug.Assert s2.Exists(c3)

    Dim c4 As Collection
    Set c4 = New Collection
    Debug.Assert Not s2.Exists(c4)
End Sub

' IObjArrayRef 测试: 异常测试，set 内同时包含基础数据类型 + 对象数据类型的数据
Private Sub test_LinkedHashSet_toObjArrayRef_error()
On Error Goto catch:
    ' 1. 生成 Set 对象
    Dim s As ISet
    Set s = UtilsSet.createLinkedHashSet

    Dim c1 As Collection
    Set c1 = New Collection

    s.Add c1
    s.Add "c2"

    ' 2. 将 set 对象转换为 ObjArray
    Dim arr As IObjArrayRef
    Set arr = s.toObjArrayRef

    Debug.Assert False
catch:
    Debug.Assert Err.Number = 10011
End Sub

' toPrimitiveArrayRef 测试
Private Sub test_LinkedHashSet_toPrimitiveArrayRef()
    ' 1. 生成 Set 对象
    Dim s As ISet
    Set s = UtilsSet.createLinkedHashSet

    s.Add "c1"
    s.Add "c2"
    s.Add "c3"

    ' 2. 将 set 对象转换为 ObjArray
    Dim arr As IPrimitiveArrayRef
    Set arr = s.toPrimitiveArrayRef

    ' 3. 检查转换结果
    Debug.Assert arr.Count = 3

    ' 创建一个新的 set 来合并数组引用并进行检查
    Dim s2 As ISet
    Set s2 = UtilsSet.createLinkedHashSet
    s2.mergePrimitiveArrayRef arr

    Debug.Assert s2.Count = 3
    Debug.Assert s2.Exists("c1")
    Debug.Assert s2.Exists("c2")
    Debug.Assert s2.Exists("c3")
    Debug.Assert Not s2.Exists("c4")
End Sub

' toPrimitiveArrayRef 测试: 异常测试，set 内同时包含基础数据类型 + 对象数据类型的数据
Private Sub test_LinkedHashSet_toPrimitiveArrayRef_error()
On Error Goto catch:
    ' 1. 生成 Set 对象
    Dim s As ISet
    Set s = UtilsSet.createLinkedHashSet

    Dim c1 As Collection
    Set c1 = New Collection
    s.Add c1
    s.Add "c2"

    ' 2. 将 set 对象转换为 ObjArray
    Dim arr As IPrimitiveArrayRef
    Set arr = s.toPrimitiveArrayRef
catch:
    Debug.Assert Err.Number = 10004
End Sub
